/*
 * Copyright (c) 2024 Black Sesame Technologies
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _DAL_STRING_SEQUENCE_H_
#define _DAL_STRING_SEQUENCE_H_
#include <stdint.h>
#include <stddef.h>

#include "dal_string.h"

#ifdef __cplusplus
extern "C" {
#endif

#define DEFAULT_STR_SEQ_CAPACITY 0xff
#define DEFAULT_STR_SEQ                                                                            \
    {                                                                                              \
        0, 0, 0                                                                                    \
    }

// after using this structure, you must call 'string_seq_reset' explicitly,
// otherwise it will cause a memory leak.
typedef struct StringSeq
{
    dal_string_t* strs;
    uint64_t length;
    uint64_t capacity;
} StringSeq_t;

int string_seq_init(StringSeq_t* str_seq, uint64_t size);
int string_seq_reset(StringSeq_t* str_seq);
int string_seq_clear(StringSeq_t* str_seq);
int string_seq_expansion(StringSeq_t* str_seq, uint64_t capacity);
int string_seq_push(StringSeq_t* str_seq, dal_string_t* str);
int string_seq_pop(StringSeq_t* str_seq);
uint64_t string_seq_size(StringSeq_t* str_seq);
int string_seq_get(StringSeq_t* str_seq, dal_string_t* str, int index);
int string_seq_set(StringSeq_t* str_seq, dal_string_t* str, int index);

#define FOR_ALL_STRING(str_seq, str, operations)                                                   \
    for (uint64_t index = 0; index < (str_seq)->length; ++index) {                                 \
        dal_string_t str = (str_seq)->strs[index];                                                 \
        operations;                                                                                \
    }

typedef struct dal_stringseq {
  uint32_t n;
  char **strs;
} dal_stringseq_t;

#ifdef __cplusplus
}
#endif

#endif  // _DAL_STRING_SEQUENCE_H_